package tests;

import static org.junit.Assert.fail;
import static util.Constant.STR_EXCEPTION_SHOULD_HAVE_OCCURED;
import static util.Constant.STR_INVALID_ID;

import org.junit.Assert;
import org.junit.Test;

import base.Tag;

public class TagTest {

	@Test
	public void testTag() {
		Tag tag = new Tag();
		Assert.assertNotNull(tag);
	}

	@Test
	public void testTagString() {
		Tag tag = new Tag("Nom du tag");
		Assert.assertNotNull(tag);
	}

	@Test
	public void testTagIntString() {
		try {
			Tag tag = new Tag(-1, "Tag invalide");
			System.out.println(tag);
			fail(STR_EXCEPTION_SHOULD_HAVE_OCCURED);
		} catch (IllegalArgumentException e) {
			Assert.assertEquals(e.getMessage(), STR_INVALID_ID);
		}

	}

	@Test
	public void testSetName() {
		Tag tag = new Tag("My tag");
		String expected = "My New Name";
		tag.setName(expected);
		Assert.assertEquals(tag.getName(), expected);
	}

	@Test
	public void testGetName() {
		String expected = "My tag";
		Tag tag = new Tag(expected);
		Assert.assertEquals(tag.getName(), expected);
	}

	@Test
	public void testGetID() {
		Integer ID = new Integer(3);
		Tag tag = new Tag(ID, "My tag");
		Assert.assertEquals(tag.getID(), ID);
	}

	@Test
	public void testEqualsObject() {
		Tag tag1 = new Tag(3, "Tag");
		Tag tag2 = new Tag(4, "Tag");

		Assert.assertFalse(tag1.equals(tag2));

		Tag tag3 = new Tag(3, "Tag");
		Assert.assertTrue(tag1.equals(tag3));
	}

}
